home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / What's New? / Development Kits / Mac OS / USB DDK 1.4.6f4 / Examples / PrinterClassDriver / PrintChooserSample / Utils.cp < prev    next >
Encoding:
Text File  |  2000-09-25  |  2.9 KB  |  139 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Utils.cp
  3.  
  4.     Contains:    General utilities
  5.  
  6.  
  7.  
  8.     Copyright:    © 1998, 2000 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Writers:
  11.  
  12.         (gc)    Garth Cummings
  13.  
  14.     Change History (most recent first):
  15.  
  16.       <USB1>     5/11/00    gc        first checked in
  17.         22 Mar 98     gp        Created
  18.  
  19.     To Do:
  20. */
  21. #include "Utils.h"
  22.  
  23.  
  24. /*-----------------------------------------------------------------------------*
  25.  
  26.     PStrEqualCaseInsensitive
  27.     
  28.     Desc:        Compares two Pascal strings while ignoring case
  29.  
  30.     In:            string1 - string to compare
  31.                 string2 - string to compare
  32.     Out:        none
  33.     
  34.     History:
  35.  
  36.     22 Mar 98    gp        Added.
  37.     
  38. *-----------------------------------------------------------------------------*/
  39. Boolean PStrEqualCaseInsensitive( Str255 string1, Str255 string2 )
  40. {
  41.     short    x;
  42.     char    c1, c2;
  43.     
  44.     if ( string1[0] != string2[0] )
  45.         return( false );
  46.         
  47.     for ( x=1; x<=string1[0]; x++ )
  48.     {
  49.         c1 = string1[x];
  50.         c2 = string2[x];
  51.         if ( c1 != c2 )
  52.         {
  53.             c1 &= ~32;
  54.             c2 &= ~32;
  55.             if ( (c1>='A') && (c1<='Z') && (c1 != c2) )
  56.                 return( false );
  57.         }
  58.     }
  59.     return( true );
  60. }
  61.  
  62. /*-----------------------------------------------------------------------------*
  63.  
  64.     AppendPStr
  65.     
  66.     Desc:        Copy a PASCAL style string to the source
  67.  
  68.     In:            mainStr - string to append to
  69.                 addStr - string to append
  70.     Out:        none
  71.     
  72.     History:
  73.  
  74.     22 Mar 98    gp        Added.
  75.     
  76. *-----------------------------------------------------------------------------*/
  77. void AppendPStr(StringPtr mainStr, StringPtr addStr)
  78.     {
  79.     register short    i;
  80.     register unsigned char    *pMainStr    = (unsigned char *)&mainStr[mainStr[0] + 1];
  81.     register unsigned char    *pAddStr    = (unsigned char *)&addStr[1];
  82.     register short    addLength    = (unsigned char)addStr[0];
  83.  
  84.     if (addLength)
  85.         {
  86.         // limit the ultimate length to 255 bytes
  87.         if ( ((unsigned char)mainStr[0] + addLength) > 255)
  88.             addLength    = 255 - (unsigned char)mainStr[0];
  89.  
  90.         // do the copy
  91.         for (i = 0; i < addLength; ++i)
  92.             *pMainStr++    = *pAddStr++;
  93.  
  94.         // update the count
  95.         mainStr[0]    += addLength;
  96.         }
  97.     }
  98.  
  99. /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  100.     
  101.     NameRegistryInstalled
  102.     
  103.     Desc:    Copies the contents of cell in the list hList into the string
  104.             pointed to by theString. The string is converted to a Pascal-
  105.             style string, with a preceding length byte.
  106.         
  107.         It is assumed that cell is a valid cell, that the cell contains no
  108.         more than 255 characters, and that theString and hList are not nil.
  109.  
  110.  
  111.     In:            Pointer to storage for a string.
  112.                 Coordinates of cell in list
  113.                 Handle to list
  114.  
  115.     Out:        String containing copy of cell text
  116.     
  117.     History:
  118.  
  119.             22 Mar 98    gp        Added.
  120. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
  121. void GetNameFromCell (StringPtr theString, Cell cell, ListHandle hList)
  122. {
  123.     short length;
  124.     
  125.     /*
  126.     The maximum length of the string is the size of a Str255, minus the
  127.     length byte…
  128.     */
  129.     length = sizeof(Str255) - 1;
  130.  
  131.     LGetCell((StringPtr)(theString + 1), &length, cell, hList);
  132.     
  133.     /*
  134.     Set the length byte.
  135.     */
  136.     *theString = (unsigned char) length;
  137. };
  138.  
  139.